package me.android.library.utils.android;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import com.google.common.collect.Lists;

import java.util.List;

import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@UtilityClass
public class ShareUtil {
    /**
     * 获取所有能分享的APP
     */
    @SuppressLint("QueryPermissionsNeeded")
    public List<ResolveInfo> getShareTargets() {
        List<ResolveInfo> mApps = Lists.newArrayList();
        Intent intent = new Intent(Intent.ACTION_SEND, null);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setType("image/*"); // "text/plain"
        PackageManager pm = ContextUtil.getAppContext().getPackageManager();
        mApps = pm.queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
        return mApps;
    }
}
